
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/head.ftl">
    <link href="/js/plugins/chosen/chosen.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="/js/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/js/plugins/chosen/chosen.jquery.js"></script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu = "travelcommend"/>
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">游记推荐</h1>
                </div>
            </div>
            <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/travelCommend/list.do" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">

                    <select class="form-control" name="type">
                        <option value="-1">全部</option>
                        <option value="1">周推荐</option>
                        <option value="2">月推荐</option>
                        <option value="3">攻略推荐</option>
                    </select>

                    <script>
                        $("select[name=type]").val(${qo.type})
                    </script>
                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>封面</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>推荐时间</th>
                    <th>推荐类型</th>
                    <th>操作</th>
                </tr>

                <#list pageInfo.list as t>
                <#--遍历查询得到的每一个domain对象-->
                    <tr>
                        <td>${t_index+1}</td>
                        <td><img src="${t.coverUrl!}" width="40px"></td>
                        <td>${t.title!}</td>
                        <td>${t.subTitle!}</td>
                        <td>${(t.schedule?string("yyyy-MM-dd"))!}</td>
                        <td>${t.typeDisPlay!}</td>
                        <td>
                            <a href ="javascript:;" class="updateBtn" data-json='${t.json}'>
                                修改
                            </a>
                        </td>
                    </tr>
                </#list>

            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>


<#--新增或更新-->
<div id="travelCommendModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" action="/travelCommend/saveOrUpdate.do"
                      enctype="multipart/form-data" style="margin: -3px 118px">
                    <input id="travelCommendId" type="hidden" name="id" />
                    <input id="travelCommendCoverUrl" type="hidden" name="coverUrl" />
                    <input id="travelId" type="hidden" name="travel.id"  />
                    <div class="form-group">
                        <label class="col-sm-4 control-label">标题</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title" placeholder="标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">副标题</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="subTitle" name="subTitle" placeholder="副标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="150px"/>
                            <input type="file" class="form-control" id="multipartFile" name="multipartFile" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐时间</label>
                        <div class="col-sm-6">
                            <input type="text" id="schedule" name="schedule" class="form-control" onclick="WdatePicker()">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐类型</label>
                        <div class="col-sm-6">
                            <select id="type" class="form-control"  name="type" >
                                <option value="1">周推荐</option>
                                <option value="2">月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="text-align: center">
                        <a href="/travel/releaseList.do?travelId=" target="_blank" id="skip">点击查看游记文章明细</a>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $(".updateBtn").click(function () {
            var json = $(this).data("json");
            console.log(json);
            if(json){
                $("#travelCommendId").val(json.id);
                $("#travelId").val(json.travelId);
                $("#title").val(json.title);
                $("#subTitle").val(json.subTitle);
                $("#coverUrl").attr("src",json.coverUrl);
                $("#travelCommendCoverUrl").val(json.coverUrl);
                $("#schedule").val(json.schedule);
                $("#type").val(json.type);

                //超链接查询当前的游记,传递的应该是游记的id
                //var href=$("#skip").attr("href")+json.travelId;不要存在中间变量,否则会一直累加
                $("#skip").attr("href",$("#skip").attr("href")+json.travelId)
            }


            //js选择图片后的回显
             $("#multipartFile").change(function (e) {
                 console.log(1);
                 for (var i = 0; i < e.target.files.length; i++) {
                     var file = e.target.files.item(i);
                     console.log(file);
                     if (!(/^image\/.*$/i.test(file.type))) {
                         continue; //不是图片 就跳出这一次循环
                     }
                     //实例化FileReader API
                     var freader = new FileReader();
                     freader.readAsDataURL(file);
                     freader.onload = function(e) {
                         $("#coverUrl").attr("src",e.target.result);
                     }
                 }
             })

            $("#travelCommendModal").modal("show");
        })



        $("#saveBtn").click(function () {
            $("#editForm").ajaxSubmit(function (data) {
                if(data.success){
                    location.reload();
                }else{
                    $.messager.alert("温馨提示",data.msg);
                }
            })
        })

        $("#searchForm select[name=type]").chosen();
    })

</script>
</body>
</html>